package com.zmn.oms.business.impl.conf.reply;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.oms.business.interfaces.conf.returnvisitcontent.ReplyContentBService;
import com.zmn.oms.model.entity.conf.reply.ReplyContent;
import com.zmn.oms.model.entity.conf.reply.ReplyContentQuery;
import com.zmn.oms.model.vo.conf.reply.ReplyContentVO;
import com.zmn.oms.services.interfaces.conf.reply.ReplyContentService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 类描述:回访内容ReturnVisitContentBServiceImpl
 *
 * @author linfeng
 * @since 2019/10/24/11:29
 */
@Service
public class ReplyContentBServiceImpl implements ReplyContentBService {
    private Logger logger = LoggerFactory.getLogger(ReplyContentBServiceImpl.class);

    @Resource
    private ReplyContentService replyContentService;

    @Override
    public List<ReplyContentVO> listPageByQuery(ReplyContentQuery query) {
        List<ReplyContent> items = replyContentService.listPageByQuery(query);
        List<ReplyContentVO> replyContentVOList = new ArrayList<>();
        for (ReplyContent returnVisitContent : items) {
            ReplyContentVO replyContentVO = new ReplyContentVO();
            BeanUtils.copyProperties(returnVisitContent, replyContentVO);
            String[] platIds = returnVisitContent.getPlat().split(",");
            String platName = "";
            for (int i = 0; i < platIds.length; i++) {
                if (i < platIds.length - 1) {
                    platName += (GlobalConsts.getPlatName(Integer.valueOf(platIds[i])) + "、");
                } else {
                    platName += GlobalConsts.getPlatName(Integer.valueOf(platIds[i]));
                }
            }
            replyContentVO.setPlatName(platName);
            replyContentVOList.add(replyContentVO);
        }

        return replyContentVOList;
    }

    @Override
    public List<ReplyContentVO> listByQuery(ReplyContentQuery query) {
        List<ReplyContent> items = replyContentService.listByQuery(query);
        List<ReplyContentVO> voList = new ArrayList<>();
        for (ReplyContent replyContent : items) {
            ReplyContentVO replyContentVO = new ReplyContentVO();
            BeanUtils.copyProperties(replyContent, replyContentVO);
            String[] platIds = replyContent.getPlat().split(",");
            String platName = "";
            for (int i = 0; i < platIds.length; i++) {
                if (i < platIds.length - 1) {
                    platName += (GlobalConsts.getPlatName(Integer.valueOf(platIds[i])) + "、");
                } else {
                    platName += GlobalConsts.getPlatName(Integer.valueOf(platIds[i]));
                }
            }
            replyContentVO.setPlatName(platName);
            voList.add(replyContentVO);
        }

        return voList;
    }

    @Override
    public ReplyContentVO findByKey(Integer id) {
        ReplyContent replyContent = replyContentService.findByKey(id);
        ReplyContentVO visitContentVO = new ReplyContentVO();
        BeanUtils.copyProperties(replyContent, visitContentVO);
        String[] platIds = replyContent.getPlat().split(",");
        String platName = "";
        for (int i = 0; i < platIds.length; i++) {
            if (i < platIds.length - 1) {
                platName += (GlobalConsts.getPlatName(Integer.valueOf(platIds[i])) + "、");
            } else {
                platName += GlobalConsts.getPlatName(Integer.valueOf(platIds[i]));
            }
        }
        visitContentVO.setPlatName(platName);
        return visitContentVO;
    }
}
